﻿<?php 
// configurations
include ("config.php");
// to return the eleme child using dot character
function have_child($array, $eleme_child, $search_using_key = false) {
    // default value to return
    $current_val = false;
    // if there is childs loop to get them
    $sign = config::$childsign;
    if (strpos($eleme_child, $sign)) {
        $childs = explode($sign, $eleme_child);
        foreach ($childs as $child) {
            $array = $array[$child];
        }
        $current_val = $array;
    } else {
        if ($search_using_key) {
            if (array_key_exists($eleme_child, $array)) {
                $current_val = $array[$eleme_child];
            }
        } else {
            if (in_array($eleme_child, $array)) {
                $current_val = $array[$eleme_child];
            }
        }
    }
    return $current_val;
}
// get function options ex: [name=smartic]
function get_options($options_str = false, $trace = false) {
    //$s is a string from whatever source
    if ($options_str) {
        // to collect options in array
        $options_ara = array();
        // get options from function arrg
        $special_chr = '\w\~\`\!\@\#\$\%\^\&\*\(\)\_\-\+\=\\\{\}\?\:\;\"\'\?\/\>\.\<\, ';
        if (preg_match_all("/\[([$special_chr]+=?[^]]*[^[]*)\]/D", $options_str, $match)) {
            // match count
            $match_count = count($match[1]);
            if ($match_count) {
                foreach ($match[1] as $match_child) {
                    if (strpos($match_child, '='.config::$FALSEsign) !== FALSE) {
                        $data = explode('=', $match_child, 2);
                        $options_ara[$data[0]] = '';
                    } else if (strpos($match_child, '=') !== FALSE) {
                        $data = explode('=', $match_child, 2);
                        $key = trim($data[0]);
                        $options_ara[$key] = $data[1];
                    } else {
                        $options_ara[$match_child] = TRUE;
                    }
                }
                if ($trace) {
                    echo '<pre>';
                    print_r($match);
                    print_r($options_ara);
                    echo '</pre>';
                }
                return $options_ara;
            }
        }
    }
    return FALSE;
}
// function array_intersect_key
if (!function_exists('array_intersect_key')) {
    function array_intersect_key($isec, $keys) {
        $argc = func_num_args();
        if ($argc > 2) {
            for ($i = 1; ! empty($isec) && $i < $argc; $i++) {
                $arr = func_get_arg($i);
                foreach (array_keys($isec) as $key) {
                    if (!isset($arr[$key])) {
                        unset($isec[$key]);
                    }
                }
            }
            return $isec;
        } else {
            $res = array();
            foreach (array_keys($isec) as $key) {
                if (isset($keys[$key])) {
                    $res[$key] = $isec[$key];
                }
            }
            return $res;
        }
    }
}
// function exists htmlspecialchars_decode or not
if (!function_exists("htmlspecialchars_decode")) {
    function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT) {
        return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
    }
}
?>
